<?php
/**
 * 问题model
 * @author 王涛
 * @DataTime 2018-08-02T08:46:15+0800
 */
namespace app\api\model;
use think\Model;
use app\api\model\LikenumModel;

class CarmationModel extends Model{
    protected $table = 'orange_carinformation';

    protected $createTime = 'ctime';

    protected $updateTime = 'utime';

    protected $autoWriteTimestamp = true;
    /**
     * @param $value
     * @return false|string
     * @author zhenHong~
     */
    protected function getUtimeAttr($value){
        return date('Y-m-d H:i:s',$value);
    }

    /**
     * @param $value
     * @return false|string
     * @author zhenHong~
     */
    protected function getCtimeAttr($value){
        return date('Y-m-d H:i:s',$value);
    }

    /**
     * 添加问题
     * @author 王涛
     * @DataTime 2018-08-02T08:46:15+0800
     * @param    [type]                   $addarray [description]
     * @return   成功返回id     失败返回false
     */
    public function addMation($addarray){
        $result = $this->save($addarray);
        if($result){
            return $this->id;
        }else{
            return false;
        }
    }
    /**
     * 修改问题
     * @author 王涛
     * @DataTime 2018-08-02T13:51:35+0800
     * @param    [type]                   $addarray [传入的参数属组]
     * @return   [type]                             [返回布尔值]
     */
    public function editMation($addarray){
        $result = $this->isUpdate(true)->save($addarray);
        return $result;
    }
    /**
     * 删除问题
     * @author 王涛
     * @DataTime 2018-08-02T15:17:13+0800
     * @param    [type]                   $id [description]
     * @return   [type]                       [description]
     */
    public function deleteMation($id){
        $reslt = $this
                 ->where(["id"=>$id])
                 ->update(["status"=>9]);
        return $reslt;
    }

    /**
     * @param $where
     * @param int $pageNumber
     * @param int $limit
     * @param $user_id
     * @return string
     * @throws \think\exception\DbException
     * @author zhenHong~
     */
    public function getMationList($where, $pageNumber=1, $limit=10)
    {
        $data['total'] = $this->where($where)->count();
        $data['list'] = $this
            ->where($where)
            ->page($pageNumber, $limit)
            ->order('ctime desc')
            ->select();

        return $data ?: '';
    }
    /**
     * 根据搜索条件获取资讯列表信息
     * @param $where
     * @param $offset
     * @param $limit
     */
    public function getMationCount()
    {
        return  $this->where('status', 'NEQ', 9)->count('id');
    }
    /**
     * 获取资讯详情
     * @author 王涛
     * @DataTime 2018-08-02T17:46:49+0800
     * @param    [type]                   $id [资讯id]
     * @return   [type]                       [description]
     */
    public function mationInfo($id)
    {
        $data = $this->where('status', 'NEQ', 9)->find($id);
        return $data;
    }

}
